class Solution {
public:
    int countStudents(vector<int>& students, vector<int>& sandwiches) {
        //统计喜欢圆心和方形的分别人数，然后只要栈顶元素有人喜欢就直接出栈，再让对应的人数-1，直到不能出栈或者
        //栈位空
        int count1 = 0;
        int count0 = 0;
        for(auto& e:students)
        {
            if(e == 1)
            {
                count1++;
            }
            else
            {
                count0++;
            }
        }
        for(int i = 0;i<sandwiches.size();i++)
        {
            if(sandwiches[i] == 1)
            {
                if(count1!=0)
                {
                    count1--;
                    continue;
                }
                else
                {
                    break;
                }
            }
            else
            {
                if(count0!=0)
                {
                    count0--;
                    continue;
                }
                else
                {
                    break;
                }
            }
        }
        return count1+count0;
    }
};